import { request } from "./index"
import type { CreatorModel } from "./user"

//* ----------------获取所有vedio的标签列表----------------------
export interface VideoTagModel {
  id: number
  name: string
}

export const reqVideoTags = () =>
  request<{ data: VideoTagModel[] }>({
    url: "/video/group/list",
  })

//* ---------------根据video的标签id获取video列表-----------------

export interface VideoModel {
  coverUrl: string //封面图
  title: string
  description: string
  creator: CreatorModel
  urlInfo: {
    url: string //video播放地址
  }
  vid: string
  // threadId: string
  commentCount: number //评论数
  shareCount: number //分享数
  playTime: string //播放量
  praisedCount: number //点赞量
  praised: boolean //自己是否已点赞
  subscribed: boolean //自己是否已收藏
}

interface reqVideoListResModel {
  hasmore: boolean //true为还有数据，false的话就表示已经加载完成了

  datas: { data: VideoModel }[]
}

//!offset参数是分页，从0开始
export const reqVideoList = (tagId: string | number, offset: string | number) =>
  request<reqVideoListResModel>({
    url: "/video/group",
    params: { id: tagId, offset },
  })

//* ------------收藏视频-------------------

//1是收藏，不是1的都是取消收藏
export const reqSubscribe = (vid: string, t: 1 | 0) =>
  request<null>({
    url: "/video/sub",
    params: { id: vid, t },
  })

//* ------------点赞资源-------------------
// type: 1是mv 4是电台 5是视频 6是动态
// id: 资源id,这里很坑，type是动态的时候请求的参数字段不是id而是threadId。但资源id又不知道是什么，点赞type为1的时候要的是threadId
// t: 1是收藏，不是1的都是取消收藏
export const reqLike = (id: string, type: 1 | 4 | 5 | 6, t: 1 | 0) => {
  return request<null>({
    url: "/resource/like",
    params: {
      [type === 6 ? "threadId" : "id"]: id,
      type,
      t,
    },
  })
}
